<!-- 搜索页面 -->
<style lang="less" scoped>
.m-sech-wrap {
  position: fixed;
  width:100vw;
  background-color:#f5f5f5;
  box-sizing: border-box;
}
.sech-clsfiy-wrap,
.sech-list-wrap {
  padding-top: 68px;
}
.sech-list{
  border-bottom: 1px solid #ebebeb;
}
.searchItem {
    p{
    line-height:20px;
    font-size:12px;
    color:#666;
    &:first-of-type{
      padding-top:5px;
      font-size:16px;
      line-height: 28px;
      color:#555;
    }
    &:last-of-type{
      margin-bottom:5px;
    }
  }
}

</style>

<template>
  <div>
    <app-header></app-header>
    <div class="m-sech-wrap displayflex">
      <div class="flex1">
        <div class="m-sech-box displayflex">
          <i class="iconfont icon-search"></i>
          <div class="flex1 m-sech-ipt">
            <input type="text" :placeholder="placeholderName" v-model="searchTxt" id="sechIpt">
          </div>
          <i class="iconfont icon-del-black" v-if="searchTxt" @click="searchTxt = ''"></i>
        </div>
      </div>
      <div class="m-sech-btn" @click="backSech(searchTxt, 'stock', $route.query.tabNo)" v-if="types == 'stock'">确定</div>
      <div class="m-sech-btn" @click="backSech(searchTxt, 'settle', $route.query.tabNo)" v-else-if="types == 'settle'">确定</div>
      <div class="m-sech-btn" @click="backSech(searchTxt, 'customDelivery', $route.query.tabNo)" v-else-if="types == 'customDelivery'">确定</div>
      <div class="m-sech-btn" @click="backSech(searchTxt)" v-else>确定</div>
    </div>
    <div class="sech-clsfiy-wrap" v-if="types == 'place'">
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="" @change="classfiyf">
        <span class="txt">所有</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="04" @change="classfiyf">
        <span class="txt">药品</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="01" @change="classfiyf">
        <span class="txt">普耗</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="02" @change="classfiyf">
        <span class="txt">跟台高值</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy"  value="03" @change="classfiyf">
        <span class="txt">备货高值</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="05" @change="classfiyf">
        <span class="txt">后勤物资</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="06" @change="classfiyf">
        <span class="txt">消毒用品</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="07" @change="classfiyf">
        <span class="txt">洗涤用品</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="08" @change="classfiyf">
        <span class="txt">中药材</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="09" @change="classfiyf">
        <span class="txt">设施设备</span>
      </label>
      <label class="label">
        <input type="radio" name="clsfiy" v-model="classfiy" value="10" @change="classfiyf">
        <span class="txt">其他</span>
      </label>
    </div>
    <div class="sech-list-wrap" v-if="todolist.length>0 && searchTxt">
      <ul class="sech-list" v-for="items in todolist">
        <template v-if="types == 'statement'">
          <li @click="backSech(items.SettleCorpName)">{{items.SettleCorpName}}</li>
        </template>
        <template v-if="types == 'receipt'">
          <li @click="backSech(items.SaleCorpName)">{{items.SaleCorpName}}</li>
        </template>
        <template v-if="types == 'place'">
          <li @click="backSech(items.GoodsName)">{{items.GoodsName}}</li>
        </template>
        <template v-if="types == 'onlyCustom'">
          <li @click="backSech(items.Name)">{{items.Name}}</li>
        </template>
        <template v-if="types == 'user'">
          <li @click="backSech(items.CreateUserName)">{{items.CreateUserName}}</li>
        </template>
        <template v-if="types == 'stock'">
          <li @click="backSech(items.GoodsName, 'stock', $route.query.tabNo)">{{items.GoodsName}}</li>
        </template>
        <template v-if="types == 'settle'">
          <li @click="backSech(items.SettleBillNo, 'settle', $route.query.tabNo)">{{items.SettleBillNo}}</li>
        </template>
        <template v-if="types == 'LogisticOrder'">
          <div class="searchItem" @click="backSech(items.BillNo)">
            <p>客户名称：{{items.MedName}}</p>
            <p>订单号：{{items.BillNo}}</p>
            <p>品种数：{{items.CountSum}}个</p>
            <p>订单时间：{{items.InputDate | timeshort}}</p>
          </div>
        </template>
      </ul>
    </div>

    <div class="noDate_page" v-if="todolist.length <= 0 && webLoad === true">
      <div class="noDate_icon"><i class="iconfont icon-null"></i></div>
      暂无数据！
    </div>
  </div>
</template>

<script>
import appHeader from '@/components/core/header/app_header.vue';
export default {
  components:{
    appHeader
  },
  data () {
    return {
      placeholderName:'',
      searchTxt:'',
      query:{},
      methodName:'',
      todolist:[],
      classfiy:'',
      TotalRecords:'',
      webLoad:false,
    }
  },
  computed:{
    types(){
      return this.$route.query.type;
    }
  },
  watch:{
    searchTxt(val){
      if(val){
        this.getData();
      }else{
        sessionStorage.sechtxt = '';
      }
    },
  },
  created(){
    this.searchTxt = sessionStorage.sechtxt;
    this.classfiy = sessionStorage.classfiy;
  },
  mounted() {
    this.$nextTick(() => {
      this.resetDate();
      $("#sechIpt").focus();
    })
  },
  methods:{
    classfiyf(){
      sessionStorage.classfiy = this.classfiy;
      this.$router.go(-1);
    },
    resetDate(){
      var userinfo = JSON.parse(localStorage.userinfo);
      var queryString = this.$route.query,
          BespeakType = queryString.BespeakType;

      //这里根据页面判断是否需要传入StaffID
      if(BespeakType == 2 || BespeakType == 3 || BespeakType == 4){
        userinfo.StaffID = '';
      }
      switch(this.types){
        //下订单
          case 'place':
          this.placeholderName = "搜索商品";
          this.query = {
            StaffGuid: userinfo.StaffID,
            GoodsName: this.searchTxt,
            GoodsCate:this.classfiy,
            PageIndex: 1,
            PageSize: 999,
          }
          this.methodName = 'Getmfgoods';
          break;

        //结算单
        case 'statement' :
          this.placeholderName = "输入结算单位";
          this.query={
            TenantGuid: userinfo.TenantGUID,
            SettleBillNo: '',
            SettleCorpName: this.searchTxt,
            InvoiceState: '',
          }
          this.methodName = 'getSettle';
          break;

        //回单
        case 'receipt' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            TenantGuid: userinfo.TenantGUID,
            BBillNo: this.searchTxt,
            CorpGuid: userinfo.CorpGuid,
            BuyerGUID: userinfo.StaffID,
            Page: 0,
            Rows: 8,
          }
          this.methodName = 'getReceiptOrder';
          break;

        //客户
        case 'onlyCustom' :
          this.placeholderName = "搜索客户";
          this.query={
            DistrbGuid: userinfo.StaffID,
            Name: this.searchTxt,
            Page: 0,
            Rows: 8,
          }
          this.methodName = 'SearchManagedHospital';
          break;

        //客户+单号 订单跟踪
        case 'custom' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            BuyerGUID: userinfo.StaffID,
            CorpGuid: userinfo.CorpGuid,
            MedName: this.searchTxt,
            BillNo: this.searchTxt,
            Page: 0,
            Rows: 999,
          }
          this.methodName = 'NewSearchOrderCode';
          break;

        //客户+单号 待受理订单列表
        case 'customAccept' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            MedName: this.searchTxt,
            BillNo: this.searchTxt,
            BillState: '',
            BillStateS:'P11',
            BuyerGUID: userinfo.StaffID,
            CorpGuid: userinfo.CorpGuid
          }
          // this.methodName = 'NewSearchOrderCode';
          this.methodName = null;
          break;


        //客户+单号 预约订单列表
        case 'customAppoint' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            MedName: this.searchTxt,
            BillNo: this.searchTxt,
            billState: queryString.billState,
            billStateS: queryString.billStateS,
            BuyerGUID: userinfo.StaffID,
            CorpGuid: userinfo.CorpGuid,
            BespeakType: queryString.BespeakType,
            Page: 0,
            Rows: 999,
          }
          // this.methodName = 'NewSearchOrderCodeBespeak';
          this.methodName = null;
          break;

        //客户+单号 受理订单列表
        case 'customReceipt' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            MedName: this.searchTxt,
            BillNo: this.searchTxt,
            BillState: 'P07',
            BillStateS:'P07',
            BuyerGUID: userinfo.StaffID,
            CorpGuid: userinfo.CorpGuid
          }
          // this.methodName = 'NewSearchOrderCode';
          this.methodName = null;
          break;

        //客户+单号 业务经理
        case 'customManage' :
          this.placeholderName = "输入客户名称或单号";
          this.query = {
            CorpGuid: userinfo.CorpGuid,
            MedName: this.searchTxt,
            BillNo: this.searchTxt,
            Page: 0,
            Rows: 999,
          }
          // this.methodName = 'SearchOrderCode';
          this.methodName = null;
          break;

        //客户+单号 erp订单列表
        case 'customErp' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            BespeakGUID: userinfo.StaffID,
            TenantGuid: userinfo.TenantGUID,
            listGuid: ['P03','P08','P11'],
            CorpGuid: userinfo.CorpGuid,
            MedName: this.searchTxt,
            BillNo: this.searchTxt
          }
          // this.methodName = 'NewSearchMedpoStateCode';
          this.methodName = null;
          break;

        // //客户+单号 安排发货出库，订单列表 
        // case 'customDelivery' :
        //   this.placeholderName = "输入客户名称或单号";
        //   this.query={
        //     BespeakGUID: userinfo.StaffID,
        //     TenantGuid: userinfo.TenantGUID,
        //     listGuid: ['P05','P07','P08'],
        //     CorpGuid: userinfo.CorpGuid,
        //     MedName: this.searchTxt,
        //     BillNo: this.searchTxt
        //   }
        //   // this.methodName = 'NewSearchMedpoStateCode';
        //   this.methodName = null;
        //   break;

        //客户+单号 提货交接-待提货 
        case 'customDelivery' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            BespeakGUID: userinfo.StaffID,
            LogState:'51',
            MedName: this.searchTxt,
            BillNo: this.searchTxt
          }
          // this.methodName = 'NewSearchOrderDelivery';
          this.methodName = null;
          break;

        //客户+单号 提货交接-已提货 
        case 'customDeliveryBillState' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            BespeakGUID: userinfo.StaffID,
            TenantGuid: userinfo.TenantGUID,
            listGuid: ['P07','P09','P10'],
            CorpGuid: userinfo.CorpGuid,
            MedName: this.searchTxt,
            BillNo: this.searchTxt
          }
          this.methodName = 'NewSearchMedpoStateCode';
          break;


        //客户+单号 签收交接-待签收 
        case 'customConLogState' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            BespeakGUID: userinfo.StaffID,
            LogState:'52',
            MedName: this.searchTxt,
            BillNo: this.searchTxt
          }
          // this.methodName = 'NewSearchOrderDelivery';
          this.methodName = null;
          break;

        //客户+单号 签收交接-已签收 
        case 'customConBillState' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            BespeakGUID: userinfo.StaffID,
            TenantGuid: userinfo.TenantGUID,
            listGuid: ['P07'],
            CorpGuid: userinfo.CorpGuid,
            MedName: this.searchTxt,
            BillNo: this.searchTxt
          }
          this.methodName = 'NewSearchMedpoStateCode';
          break;

        //客户+单号 签收签收 
        case 'customSign' :
          this.placeholderName = "输入客户名称或单号";
          this.query={
            MedName:this.sechTxt,
            BillNo:this.sechTxt,
            MedGuid: userinfo.BelongGuid,
            StateList: ['P03','P04','P05','P06','P07','P08','P09','P10'],
            LogState: ''
          }
          // this.methodName = 'NewSearchOrderSign';
          this.methodName =null;
          break;

        //用户
        case 'user' :
          this.placeholderName = "输入用户名称";
          this.query={
            TenantGUID: userinfo.TenantGUID,
            CorpGuid: userinfo.CorpGuid,
            Name:this.searchTxt || ''
          }
          this.methodName = 'SearchMfstaffbacies';
          break;

        case 'stock' :
          var tabNo = this.$route.query.tabNo,
              url = 'getMedStock',
              query = {
                GoodsName: this.searchTxt,
                PageIndex: 1,
                PageSize: 999999,
                StaffGuid: userinfo.StaffID,
              };
          this.placeholderName = "商品名称";
          if(tabNo === 2){
            url = 'getLotMedStock';
            this.placeholderName = "商品名称/批号";
            query.Lot = this.searchTxt;
          }
          
          this.query = query;
          this.methodName = url;
          break;

        case 'settle' :
          this.placeholderName = "结算单号/供应商名称";
          this.methodName = null;
          break;
        
        case 'supplier':
          this.placeholderName = "供应商名称";
          this.methodName = null;
          break;

        case 'LogisticOrder':
          this.placeholderName = "输入客户名称或单号";
          let MedGuid = '',
              BuyerGUID = userinfo.StaffID;

          if (userinfo.UserBizType=='Hospital') {
            MedGuid = userinfo.BelongGuid;
            BuyerGUID = '';
          }
          if (userinfo.UserBizType=='ServiceManager') {
              BuyerGUID = '';
          }

          let query = {
            KeyWord:this.searchTxt,
            MedGuid:MedGuid,
            BuyerGUID: BuyerGUID,
            CorpGuid: userinfo.CorpGuid,
            TenantGuid: userinfo.TenantGuid,
            PageIndex: 1,
            PageSize: 999999,
          }
          this.query = query;
          this.methodName = 'SearchLogisticOrder';
          break;

        case 'MedGoods':
          this.placeholderName = "输入商品名称";
          this.methodName = null;
          break;
      }
    },
    
    getData(){
      this.resetDate();
      let self = this;
      if(this.methodName != null) {
        this.webLoad = true;
        this.Ajax.post(this.methodName, this.query).then((resp) => {
          this.TotalRecords = resp.TotalRecords;
          this.todolist = resp.Datas;
          if(this.types === 'onlyCustom'){
            let hash = {};
            this.todolist = this.todolist.reduce((item, next) => {
              if (!hash[next.Name]) {
                hash[next.Name] = true;
                item.push(next);
              }
              return item;
            }, []);
          }
        });
      }
    },
    backSech(val, tabType, tabNo){
      if(val){
        sessionStorage.sechtxt = val;
      }else{
        sessionStorage.sechtxt = '';
      }

      if(tabType == 'stock'){
        sessionStorage.setItem('StockTab',tabNo);
      }
      if(tabType == 'settle'){
        sessionStorage.setItem('SettleTab',tabNo);
      }
      // if(tabType == 'customDelivery'){
      //   sessionStorage.setItem('ConsumableTab',tabNo);
      // }
      this.$router.go(-1);
    }
  },
}
</script>
